package com.qf.lanzhou.shop.api.controller;

import com.qf.lanzhou.shop.pojo.entity.Feedback;
import com.qf.lanzhou.shop.pojo.entity.User;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import com.qf.lanzhou.shop.api.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author jian    反馈
 * @Date 2021/1/9 17:19
 * @JDK 1.8
 * @Version 1.0
 */
@Api("反馈信息")
@Controller
public class FeedbackController extends BaseController{

    @Autowired
    private FeedbackService feedbackService;


    @ApiOperation(value = "买家匿名反馈信息接口")
    @PostMapping(value = "/feedback")
    @ResponseBody
    public BaseRespVO insertfeed(String shopName,String message, HttpServletRequest req){
        System.out.println(shopName);
        System.out.println(message);

        //查询卖家名是否存在
        Feedback feedback=feedbackService.selectName(shopName);
        if(feedback==null){
            return convertErrorResult("填写错误,请重新填写");
        }
        else {
            int i = feedbackService.insert(shopName, message);
            if (i == 1) {
                System.out.println("反馈成功");
                return convertSuccessResult(feedback);
            }
        }
        //返回错误信息,添加不成功
        return convertErrorResult("填写错误,请重新填写");
    }



    @ApiOperation(value = "买家实名反馈信息接口")
    @PostMapping(value = "/feedbackname")
    @ResponseBody
    public BaseRespVO insertfeedname(String shopName,String message,String userName,HttpServletRequest req){
        System.out.println(shopName);
        System.out.println(message);
        //查询卖家名是否存在
        Feedback feedback=feedbackService.selectName1(shopName);
        if(feedback==null){
            return convertErrorResult("填写错误,请重新填写");
        } else {
                int i = feedbackService.insertid(shopName, message,userName);
                if (i == 1) {
                    System.out.println("反馈成功");
                    return convertSuccessResult(feedback);
                }

        }
        //返回错误信息,添加不成功
        return convertErrorResult("填写错误,请重新填写");
    }

}
